/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MODEL;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

/**
 *
 * @author Irene
 */
public class ResearchHandler extends Observable implements Observer, Serializable {

    private List<Research> researchNotes;
    private Research activeResearchNote;

    public ResearchHandler() {
        researchNotes = new ArrayList<Research>();
    }

    /* adds a researchnoteToList and notifies observers
     * @param r is the object to be added
     */
    public void addResearchNoteToList(Research r) {
        researchNotes.add(r);
        setChanged();
        notifyObservers();

        r.addObserver(this);
    }

    /* Removes the researchNoteFromList and notifies observers
     * @param reserch is the object to be removed
     */
    public void removeResearchNoteFromList(Object research) {
        researchNotes.remove(research);
        setChanged();
        notifyObservers();

        activeResearchNote.deleteObserver(this);
    }

    public List<Research> getResearchNotes() {
        return researchNotes;
    }

    public Research getActiveResearchNote() {
        return activeResearchNote;
    }

    /*sets the active research and notifies observers
     * @param research is the object to be active
     */
    public void setActiveResearch(Research research) {
        activeResearchNote = research;
        setChanged();
        notifyObservers();
    }

    public void update(Observable o, Object arg) {
        setChanged();
        notifyObservers();
    }
}
